package com.yf.springboot.service.impl;

import com.yf.springboot.entity.User;
import com.yf.springboot.service.UserService;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    private Counter counter;

    public UserServiceImpl(MeterRegistry meterRegistry) {
        counter = meterRegistry.counter("userService.getUser.count");
    }

    public User findUserById(Long id) {
        User user = new User();
        user.setId(id);
        // 每被调用一次就加1
        counter.increment();

        return user;
    }
}
